package com.cvte.shop.service.rest;

import com.cvte.csb.core.interfaces.vo.RestResponse;
import com.cvte.csb.web.rest.ResponseFactory;
import com.cvte.csb.web.swagger.annonation.ApiResponse;
import com.cvte.csb.web.swagger.annonation.ApiResponseDoc;
import com.cvte.csb.web.swagger.annonation.ApiVersion;
import com.cvte.csb.web.swagger.annonation.ApiVersionDoc;
import com.cvte.shop.annotation.EableLog;
import com.cvte.shop.entity.ShopUserAll;
import com.cvte.shop.service.ShopUserAllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author DaiShubo
 * @version 1.0
 * @description 用户rest接口
 * @createTime 2020/7/27 8:22 下午
 * @since 1.7
 **/
@Api(tags = "用户接口")
@RestController
@RequestMapping("/user")
public class RestUserController {

    @Autowired
    private ShopUserAllService shopUserAllService;

    /**
     * 查询整个用户列表
     * @return
     */
    @EableLog
    @ApiOperation("查询所有用户列表")
    @GetMapping("/users")
    public RestResponse selectAllUserList(){
        List<ShopUserAll> shopUserAlls = shopUserAllService.listUser();
        return ResponseFactory.getOkResponse(shopUserAlls);
    }

    /**
     * 根据主键查询用户信息
     * @param id        用户的主键
     * @return
     */
    @ApiResponseDoc({
            @ApiResponse(key = "id", value = Long.class),
    })
    @ApiOperation("根据id获取相应的用户信息")
    @GetMapping("/user/{user_id}")
    public RestResponse getUserById(@PathVariable("user_id") String id){
        ShopUserAll shopUserAll = shopUserAllService.getUserById(id);
        return ResponseFactory.getOkResponse(shopUserAll);
    }

    /**
     * 更新用户昵称
     * @param userId        用户的主键
     * @param nickname      昵称名字
     * @return
     */
    @ApiResponseDoc({
            @ApiResponse(key = "userId", value = String.class),
            @ApiResponse(key = "nickname", value = String.class),
    })
    @ApiOperation("更新用户昵称")
    @GetMapping("/update_user")
    public RestResponse updateUser(String userId,String nickname){
        shopUserAllService.updateUserNickname(userId,nickname);
        return ResponseFactory.buildResult("更新成功");
    }

    /**
     * 删除用户
     * @param userId        用户的主键
     * @return
     */
    @ApiResponseDoc({
            @ApiResponse(key = "userId", value = String.class),
    })
    @ApiOperation("删除用户")
    @GetMapping("/delete_user")
    public RestResponse deleteUser(String userId){
        shopUserAllService.deleteUser(userId);
        return ResponseFactory.buildResult("删除成功");
    }


}
